/*
//
//              INTEL CORPORATION PROPRIETARY INFORMATION
//  This software is supplied under the terms of a license  agreement or
//  nondisclosure agreement with Intel Corporation and may not be copied
//  or disclosed except in  accordance  with the terms of that agreement.
//    Copyright (c) 2007-2008 Intel Corporation. All Rights Reserved.
//
//
*/

#ifndef __UMC_AVS_FUSION_CORE_H
#define __UMC_AVS_FUSION_CORE_H

#include "ippdefs.h"
#include "umc_structures.h"
#include "umc_avs_list.h"
#include "umc_avs_sequence_header.h"
#include "umc_avs_picture_header.h"

#include "umc_mutex.h"

namespace UMC
{

// forward declaration of used types
class MediaData;
class BaseCodecParams;
class AVSProcessingUnit;
class AVSFrame;
class AVSSlice;
class AVSMemory;

class AVSFusionCore
{
public:
    // Default constructor
    AVSFusionCore(void);
    // Destructor
    virtual
    ~AVSFusionCore(void);

    // Initialize the core
    virtual
    Status Init(Ipp32u numThreads, BaseCodecParams *pParams);
    // Reset the core
    Status Reset(void);
    // Add a piece of source data to the core
    virtual
    Status LoadSource(MediaData *pSrc) = 0;
    // Set destination fideo frame
    virtual
    Status SetDestination(MediaData *pDst) = 0;

    // Get next available task
    AVSProcessingUnit *GetTask(Ipp32u threadNum);

protected:
    // Release the object
    Status Release(void);

    //
    // Following 3 functions are designed to get free
    // units. Functions looks in free queues and if nothing is found
    // call allocating functions.

    // Obtain one more unused frame
    AVSListElement<AVSFrame> *GetFreeFrame(void);
    // Obtain one more slice object
    AVSListElement<AVSSlice> *GetFreeSlice(bool bLargeCoeffsBuffer = true);
    // Obtain one more memory piece
    AVSListElement<AVSMemory> *GetFreeMemoryPiece(size_t nSize);

    // Allocate one more frame
    virtual
    AVSListElement<AVSFrame> *AllocateFrame(void);
    // Allocate one more slice
    virtual
    AVSListElement<AVSSlice> *AllocateSlice(void);

    // Initialize the frame
    virtual
    Status InitializeFrame(AVSFrame *pFrame);
    // De-initialize the frame
    Status PurgeFrame(AVSFrame *pFrame);

    // Create frame's reference list
    Status CreateReferenceLists(AVSFrame *pFrame);

    //
    // these members could be accessed without synchronization
    //

    AVSList<AVSFrame> m_FreeFrames;                             // (AVSList<AVSFrame>) the list of free frames
    AVSList<AVSSlice> m_FreeSlices;                             // (AVSList<AVSSlice>) the list of free slices
    AVSList<AVSMemory> m_FreeMemory;                            // (AVSList<AVSMemory>) the list of free memory pieces

    AVSList<AVSProcessingUnit> *m_pPerformers;                  // (AVSList<AVSProcessingUnit> *) pointer to an array of performers
    Ipp32u m_numThreads;                                        // (Ipp32u) current number of working threads
    Ipp32u m_maxFrames;                                         // (Ipp32u) maximum allowed number of allocated frames

    AVS_SEQUENCE_HEADER m_seqHeader;                            // (AVS_SEQUENCE_HEADER) sequence header
    AVS_PICTURE_HEADER m_picHeader;                             // (AVS_PICTURE_HEADER) picture header

    Ipp32u m_numFrames;                                         // (Ipp32u) number of allocated frames

    Ipp32u m_curFrameNum;                                       // (Ipp32u) current frame ordinal number

    Mutex m_guard;                                              // (Mutex) the sync object

    //
    // these members could be accessed only through synchronization
    //

    AVSList<AVSFrame> m_Frames;                                 // (AVSList<AVSFrame>) pointer to being processed frame(s)
};

} // namespace UMC

#endif // __UMC_AVS_FUSION_CORE_H
